﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Proje
{
    class EmployeeFileConnector
    {
        FileStream file;
        StreamReader reader;
        StreamWriter writer;

        public Boolean insert(Employee employee)
        {
            try
            {
                file = new FileStream(FilePath, FileMode.Append);
                writer = new StreamWriter(file);
                String recordString = createInsertString(employee);
                writer.WriteLine(recordString);
                return true;
            }
            catch (IOException e)
            {
                return false;
            }
            finally
            {
                writer.Close();
                file.Close();
            }
            
        }

        private string createInsertString(Employee employee)
        {
            return string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|", employee.tcNo,
                                                    employee.name,
                                                    employee.lastName,
                                                    employee.birthdate,
                                                    employee.salary,
                                                    employee.phone,
                                                    employee.position);
        }

        private String FilePath
        {
            get
            {
                return @"C:\\Users\Desktop\Serhat\Proje\EMPLOYEE";
            }
        }
    }
}
